//阅读领取奖励金币之后，看广告再领
var read_ad = {
  go_page_from_home() {},
  start() {
    console.log("read_ad start");
    sleep(2 * 1000);
    this.init();
  },
  init() {
    var ui_text = utils.exists_text_starts_with("看广告再领");
    if (ui_text) {
      console.log("read_ad init: 找到【看广告再领】");
      var gold = utils.get_gold(ui_text.text());
      console.log("read_ad init: " + gold + "金币");
      if (gold > constant.min_gold) {
        utils.click_text_starts_with("看广告再领");
        sleep(constant.min_click_after_time * 1000);
        ad_util.execute();
        this.next();
      } else {
        console.log("read_ad init: 广告金币太少");
        sleep(constant.min_click_after_time * 1000);
        this.next();
      }
    } else {
      console.log("read_ad init: 没找到【看广告再领】");
      this.next();
    }
  },
  next() {
    console.log("read_ad next");
    if (utils.exists_text_starts_with("看广告再")) {
      console.log("read_ad next: 找到【看广告再】");
      this.init();
      return;
    }
    if (utils.click_text("开心收下")) {
      console.log("read_ad next: 找到【开心收下】");
      sleep(constant.min_click_after_time * 1000);
    }
    if (utils.click_text("立即收下")) {
      console.log("read_ad next: 找到【立即收下】");
      sleep(constant.min_click_after_time * 1000);
    }
  },
};
